import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;

/**
 * Ninja Class
 * @author Hugo Armando Rodriguez Flores
 * @version April 23th 2013
 */
public abstract class Ninja extends Actor
{
    private int moveCounter; //counter that indicates a movement image to be displayed
    private int attackCounter; //counter that indicates a hit image to be displayed
    private boolean direction; //actual direction of the character. false ->, true <-
    private boolean dirFlag; //this sets true when direction change is known.
    private ArrayList<GreenfootImage> img; //ArrayList that stores all the given images.
    
    /**
     * It creates a new ArrayList with objects of class GreenfootImage
     */
    public Ninja()
    {
        img=new ArrayList<GreenfootImage>();
        attackCounter=moveCounter=0;
        dirFlag=direction=false;
    }
    
    /**
     * This store images for any Ninja
     * @param imagesNum is the number of images to be stored on the ArrayList
     * @param name is the name of the image file to be stored (without extension)
     */
    public void storeImages(int imagesNum, String name)
    {
        String tempString=new String();
        for (int i=0; i<imagesNum; i++)
        {
            tempString=name+(i+1)+".png";
            img.add(new GreenfootImage(tempString));
        }
    }
    
    /**
     * It gets a specified element from the ArrayList
     * @param index is the position where the element to be returned is
     * @return a GreenfootImage object
     */
    public GreenfootImage getElement(int index)
    {
        return img.get(index);
    }
    
    /**
     * This reverses the images contained in the ArrayList
     */
    public void reverseImages()
    {
        if (this.getDirectionFlag())
        {
            for (GreenfootImage it: img)
                it.mirrorHorizontally();
            this.setDirectionFlag(false);
        }
    }
    
    /**
     * It returns the current value of the counter
     * @return the move counter
     */
    public int getMoveCounter()
    {
        return moveCounter;
    }
    
    /**
     * It sets a value to the counter
     * @param anInteger is the new value to be asigned to the counter
     */
    public void setMoveCounter(int anInteger)
    {
        moveCounter=anInteger;
    }
    
    /**
     * This increments the counter
     */
    public void moveCounterIncr()
    {
        moveCounter++;
    }
    
    /**
     * It returns the current value of the counter
     * @return the attack counter
     */
    public int getAttackCounter()
    {
        return attackCounter;
    }
    
    /**
     * It sets a value to the counter
     * @param anInteger is the new value to be asigned to the counter
     */
    public void setAttackCounter(int anInteger)
    {
        attackCounter=anInteger;
    }
    
    /**
     * This increments the counter
     */
    public void attackCounterIncr()
    {
        attackCounter++;
    }
    
    /**
     * Sets a new direction for this character
     * @param newDirection is the new direction that the character will take
     */
    public void setDirection(boolean newDirection)
    {
        direction=newDirection;
    }
    
    /**
     * @return the current direction of this character
     */
    public boolean getDirection()
    {
        return direction;
    }
    
    /**
     * Sets a new flag when a change in the direction is known
     * @param newFlag sets true when a change in the direction is known
     */
    public void setDirectionFlag(boolean newFlag)
    {
        dirFlag=newFlag;
    }
    
    /**
     * @return the current direction flag of this character
     */
    public boolean getDirectionFlag()
    {
        return dirFlag;
    }
    
    /**
     * Realocates a ninja in the world and puts its corresponding animation
     * @param newX is the increment in x to position the entity in the world
     * @param newY is the increment in y to position the entity in the world
     */
    public void realocate(int newX, int newY)
    {
        this.setLocation(getX()+newX, getY()+newY);
        this.movementAnimation();
    }
    
    /**
     * All ninjas have an animation
     */
    public abstract void movementAnimation();
    
    /**
     * All ninjas attack
     */
    public abstract void attack();
}
